Build Install and Launch iOS app on Simulator

Build

1
2
# build
xcodebuild -scheme TestApp DSTROOT=./tmp archive

Install

1
2
# list simluator devices
xcrun simctl list -j devices
1
2
3
4
5
6
# list simluator device types
xcrun simctl list -j devicetypes | jq -r '.devicetypes[].name'
...
iPhone 7
iPhone 7 Plus
...
1
2
3
4
5
6
# get UDID by device type
export SIM_DEVICE_TYPE='iPhone 7'
UDID=$(\
xcrun simctl list -j devices | \
jq -r '.devices."iOS 10.2"[] | select(.name==env.SIM_DEVICE_TYPE) | .udid' \
)
1
2
3
4
5
# launch simluator
xcrun instruments -w $UDID
# or
SIM_APP='/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app'
open -a $SIM_APP --args $UDID
1
2
3
# get booted simluator
xcrun simctl list -j devices | \
jq -r '.devices."iOS 10.2"[] | select(.state=="Booted") | .udid'
1
2
# install app
xcrun simctl install booted ./TestApp-iphonesimulator.app

Launch

1
2
# launch installed app
xcrun simctl launch booted io.appium.TestApp
1
2
# terminate app
xcrun simctl terminate booted io.appium.TestApp